
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 06/13/2010 11:40:21
-- Generated from EDMX file: G:\Projetos\Controle Financeiro\ControleFinanceiro.Infra\AcessoADados\Modelo.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [CONTROLFINANC];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_BancoConta]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Contas] DROP CONSTRAINT [FK_BancoConta];
GO
IF OBJECT_ID(N'[dbo].[FK_ContaLancamento]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Lancamentos] DROP CONSTRAINT [FK_ContaLancamento];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[Bancos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Bancos];
GO
IF OBJECT_ID(N'[dbo].[Contas]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Contas];
GO
IF OBJECT_ID(N'[dbo].[Lancamentos]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Lancamentos];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'Bancos'
CREATE TABLE [dbo].[Bancos] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Codigo] nvarchar(7)  NOT NULL,
    [Nome] nvarchar(100)  NOT NULL
);
GO

-- Creating table 'Contas'
CREATE TABLE [dbo].[Contas] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Numero] nvarchar(50)  NOT NULL,
    [Agencia] nvarchar(10)  NOT NULL,
    [Saldo] float  NOT NULL,
    [Banco_Id] int  NOT NULL
);
GO

-- Creating table 'Lancamentos'
CREATE TABLE [dbo].[Lancamentos] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [DataLancamento] datetime  NOT NULL,
    [Valor] float  NOT NULL,
    [Tipo] nvarchar(1)  NOT NULL,
    [Descricao] nvarchar(max)  NOT NULL,
    [Conta_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'Bancos'
ALTER TABLE [dbo].[Bancos]
ADD CONSTRAINT [PK_Bancos]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Contas'
ALTER TABLE [dbo].[Contas]
ADD CONSTRAINT [PK_Contas]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Lancamentos'
ALTER TABLE [dbo].[Lancamentos]
ADD CONSTRAINT [PK_Lancamentos]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [Banco_Id] in table 'Contas'
ALTER TABLE [dbo].[Contas]
ADD CONSTRAINT [FK_BancoConta]
    FOREIGN KEY ([Banco_Id])
    REFERENCES [dbo].[Bancos]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_BancoConta'
CREATE INDEX [IX_FK_BancoConta]
ON [dbo].[Contas]
    ([Banco_Id]);
GO

-- Creating foreign key on [Conta_Id] in table 'Lancamentos'
ALTER TABLE [dbo].[Lancamentos]
ADD CONSTRAINT [FK_ContaLancamento]
    FOREIGN KEY ([Conta_Id])
    REFERENCES [dbo].[Contas]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_ContaLancamento'
CREATE INDEX [IX_FK_ContaLancamento]
ON [dbo].[Lancamentos]
    ([Conta_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------